package io.xxx.xbutler.event.job;

import io.xxx.xbutler.data.RobotMapper;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

@Slf4j
@Component
public class RobotRefreshJob extends QuartzJobBean {

    @Resource
    private RobotMapper robotMapper;

    @Override
    protected void executeInternal(@Nonnull JobExecutionContext context) {
        log.info("刷新机器人任务开始");
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        int count = robotMapper.refresh();

        stopWatch.stop();
        log.info("刷新机器人任务结束[{}个机器人已刷新, {}秒]", count, stopWatch.getTotalTimeSeconds());
    }
}
